/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sirafia.validadores;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
/**
 *
 * @author Sonia García
 */
public class validaTelefonoMovil  implements Validator{
 public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {

        String enteredTelefonoCasa =String.valueOf(value);
        Pattern p = Pattern.compile("[7]\\d{7}");
        Matcher m = p.matcher(enteredTelefonoCasa);


        boolean matchFound = m.matches();

        if(!matchFound)
        {
            FacesMessage message = new FacesMessage();
            message.setDetail("Campo invalido");
            message.setSummary("Campo invalido");
            throw new ValidatorException(message);
        }

    }
}